package com.sakura.flux.service;

import com.sakura.flux.entity.User;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
public class UserWebClient {
    public Mono<User> getUserById(String userId) {
        return WebClient.create()
                .get()
                .uri("http://127.0.0.1:9000/users/{userId}", userId)
                .retrieve().
                bodyToMono(User.class);
    }

    public Flux<User> getUserByUserName(String userName) {
        return WebClient.create()
                .get()
                .uri("http://127.0.0.1:9000/users/search?name={userName}", userName)
                .retrieve().
                bodyToFlux(User.class);
    }
}